<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<c:set var="base" value="${pageContext.request.contextPath}"></c:set>

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>设备管理</title>
	<link href="${base}/assets/css/public.css" rel="stylesheet">
	<link href="${base}/assets/css/jquery.searchableSelect.css" rel="stylesheet">
	<script src="${base}/assets/js/jquery.min.js"></script>
	<script src="${base}/assets/js/jquery.searchableSelect.js"></script>
	<link rel="stylesheet" type="text/css" href="${base}/assets/easyui/themes/gray/easyui.css" />
	<link rel="stylesheet" type="text/css" href="${base}/assets/easyui/themes/icon.css" />
	<script type="text/javascript" src="${base}/assets/easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="${base}/assets/easyui/locale/easyui-lang-zh_CN.js"></script>
</head>
<body>

<div class="top">
   <c:import url="../commons/top.jsp"/>
</div>
<div class="wrap">
  <div class="side">
   	<c:import url="../commons/sidebar.jsp"/>
  </div>
  <div class="cont">
    <div class="bread">
      	<span>设备管理</span><span>&nbsp;&gt;&nbsp;</span><span>添加设备</span>
      	<div class="exl">
        </div>
        <div class="excel-add">
      		<a class="add" style="float: right;margin-right: 30px;" href="javascript:void(0)" onclick="fahui()">返回</a>
        </div>
      <div class="clear"></div>
    </div>
<form method="post" action="${base}/back/userAdd.do" id="donaForm">
    <div class="form-group">
        <label>所属分类:</label>
        <div class="group-add" style="position:relative;z-index:10">
            <select  id="cid" name="cid">
               <option value="">--请选择--</option>
               <c:forEach items="${maxc}" var="m">
                   <option value="${m.id}">${m.name}</option>
               </c:forEach>
            </select>
        </div>
      <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>功能分类:</label>
        <div class="group-add" style="position:relative;z-index:9" id="fciddiv">
          <select  id="fcid" name="fcid" >
             <option value="">--请选择--</option>
                                               
         </select>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>设备分类:</label>
        <div class="group-add" style="position:relative;z-index:8" id="dciddiv">
          <select id="dcid" name="dcid" >
             <option value="">--请选择--</option>
          </select>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>品牌:</label>
        <div class="group-add">
        	<input name="brand" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>旧编号:</label>
        <div class="group-add">
        	<input name="oldno" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>编号:</label>
        <div class="group-add">
        <input id="no" name="no" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>型号:</label>
        <div class="group-add">
        	<input name="xhno" class="easyui-validatebox" data-options="required:true" placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>出厂编号:</label>
        <div class="group-add">
        	<input name="ccno" class="easyui-validatebox" data-options="required:true"/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>投产时间:</label>
        <div class="group-add">
        	<input name="tcrq" placeholder="" style="height:34px" class="easyui-datetimebox" data-options="required:true"/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>折旧年限:</label>
        <div class="group-add">
        	<input name="zjnx" class="easyui-numberbox" style="height:34px" data-options="required:true,min:0,max:100,suffix:'年'"  placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>采购价格:</label>
        <div class="group-add">
        	<input name="cgjg" class="easyui-numberbox" style="height:34px" data-options="required:true,min:0,precision:2,suffix:'元'"  placeholder=""/>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>当前位置:</label>
        <div class="group-add">
          <select id="wid" name="wid">
	         <option value="">--请选择--</option>
	         <c:forEach items="${whlist}" var="w">
	         	<option value="${w.id}" <c:if test="${w1==w.id}">selected="selected"</c:if>>${w.whname}</option>
	        </c:forEach>
	     </select>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-group">
        <label>备注：</label>
        <div class="group-add">
        	<textarea rows="2" cols="93"class="easyui-validatebox" style="width:60%;padding:10px;" placeholder="备注" name="remark"></textarea>
        </div>
        <div class="clear"></div>
    </div>
    <div class="form-actions">
        <a class="btn" style="background-color:#337ab7; color:#fff" onclick="submitDona()">提交</a>
        <button type="reset" class="btn">重置</button>
        <div class="clear"></div>
    </div>
</form>
  </div>
</div>
<div class="clear"></div>
</body>
<script>
 $(function(){
	$('#cid').searchableSelect({  
        afterSelectItem: function(){  
           var fsv= this.holder.data("value");
           if(fsv!=null && fsv!=''){
            	$.ajax({
					url: '${base}/back/searchmidc.do?pid='+fsv,
					async:false,
					dataType:"json",
					type:"post",
					success:function (data){
						$('#fciddiv').html("");
						var list = data.midc;
						if(list.length>0){
							var sel = '<select id="fcid" name="fcid" ><option value=""></option>'
							$.each(list,function(index,item){
								 sel +='<option value=" '+
										item.id + '">'+item.name+
									'</option>';
							});
							sel += '</select>';
							$('#fciddiv').append(sel);
							fcidcaozuo();
						}else{
							var sel = '<select id="fcid" name="fcid" ><option value="">无子分类</option></select>';
							$('#fciddiv').append(sel);
							$('#fcid').searchableSelect();
						} 	
					},
				});
            }
        }	 
    });
	function fcidcaozuo(){
		$('#fcid').searchableSelect({  
	        afterSelectItem: function(){  
	            var fsv= this.holder.data("value");
	            if(fsv!=null && fsv!=''){
	             	$.ajax({
	 					url: '${base}/back/searchmidc.do?pid='+fsv,
	 					async:false,
	 					dataType:"json",
	 					type:"post",
	 					success:function (data){
	 						$('#dciddiv').html("");
	 						var list = data.midc;
	 						if(list.length>0){
								var sel = '<select id="dcid" name="dcid" ><option value=""></option>'
								$.each(list,function(index,item){
									 sel +='<option value=" '+
											item.id + '">'+item.name+
										'</option>';
								});
								sel += '</select>';
								$('#dciddiv').append(sel);
								$('#dcid').searchableSelect();
							}else{
								var sel = '<select id="fcid" name="fcid" ><option value="">无子分类</option></select>';
								$('#dciddiv').append(sel);
								$('#dcid').searchableSelect();
							} 
						}, 
	 				});
	             }	
	         }  
	     });
	}
	
	$('#wid').searchableSelect(); 
	$('#fcid').searchableSelect(); 
	$('#dcid').searchableSelect();
	$("#no").change(function() { 
				var uacc = $.trim($("#no").val());
				   $.ajax({
			        type: "POST",
			        dataType: "json", // 数据格式:JSON
			        url: '${base}/back/nocheck.do?no='+uacc,
			       // data: postData,
			        success: function (data) {
			     	   if(data.ok == 'ok'){ 
			     	   }else{
			     		   alert("编号已存在！！")
			     		   return;
			     	   }
			        }
			       
			    });
		});
}); 
   function submitDona(){


	var widc = document.getElementById("wid");
	if(widc!=null){
		var wid = $('#wid option:selected') .val();
		if(wid==null || wid==""){alert("当前位置未选择！！");return;}
	}
	
	var cid = $('#cid option:selected') .val();
	var fcid= $('#fcid option:selected') .val();
	var dcid= $('#dcid option:selected') .val();
	
	if(cid==null || cid==""){alert("所属分类未选择！！");return;}
	if(fcid==null || fcid==""){alert("功能分类未选择！！");return;}
	if(dcid==null || dcid==""){alert("设备未选择！！");return;}
	 var postData = $('#donaForm').serialize();
	 $.ajax({
	        type: "POST",
	        url: '${base}/back/deviceinput.do',
	        data: postData,
	        success: function (data) {
	     	   var mymessage=window.confirm('添加成功！是否返回');  
			   if(mymessage==true){  
			   		fahui();
			   }else if(mymessage==false){  
			   		 return; 
			   }
	        }
	    }); 
   }
function fahui(){
	var url ="${base}/back/devicelist.do?pageNo=${pageNo}";
	var status='${status}';
	var wid='${wid}';
	var cid='${cid}';
	var fcid='${fcid}';
	var dcid='${dcid}';
	var no='${no}';
	if(status!=null&&status!="") url+="&status="+status;
	if(wid!=null&&wid!="") url+="&wid="+wid;
	if(cid!=null&&cid!="") url+="&cid="+cid;
	if(fcid!=null&&fcid!="") url+="&fcid="+fcid;
	if(dcid!=null&&dcid!="") url+="&dcid="+dcid;
	if(no!=null&&no!="") url+="&no="+no;
	window.location.href = url;
}

</script>
</html>



